import { Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';

@Injectable()
export class AuthService {
  @Inject(JwtService)
  private jwtService: JwtService;

  @Inject(ConfigService)
  private configService: ConfigService;

  async loginByJwt(loginMsg: Object) {
    const payload = loginMsg;
    const expiresIn = this.configService.get('auth.jwt.time');
    return {
      access_token: this.jwtService.sign(payload, {
        expiresIn,
        secret: this.configService.get('auth.jwt.token'),
      }),
      expiresIn,
    };
  }
}
